import logging
import os
import sys

import pytest

from utils.send_feishu_msg import send_feishu_message

if __name__ == "__main__":
    if len(sys.argv) == 2:
        if sys.argv[1] == "test":
            # 测试环境的地址
            os.environ["URL"] = "http://192.168.10.141/api/cloud-api"
            #根据实际情况修改字典内的数据
            os.environ["DB"] = str({
                "host": "192.168.10.141",
                "port": 3306,
                "database": "xingyun",
                "user": "root",
                "password": "123456"
            })
            os.environ["ENV"] = "test"
        elif sys.argv[1] == "prod":
            os.environ["URL"] = "http://192.168.10.141/api/cloud-api"
            os.environ["DB"] = str({
                "host": "192.168.10.141",
                "port": 3306,
                "database": "xingyun",
                "user": "root",
                "password": "123456"
            })

            os.environ["ENV"] = "prod"
        else:
            logging.info("请输入正确的执行命令:python run.py test 或者 python run.py prod")
    else:
        logging.info("请输入正确的执行命令:python run.py test 或者 python run.py prod")

    pytest.main([
        "-vs",
        "./testcases/test_runner.py",
        "--alluredir", "./report/json_report",  # 指定allure报告中间结果目录
        "--clean-alluredir"  # 清除之前的报告结果（避免新旧结果混合）
    ])
    os.system("allure generate ./report/json_report -o ./report/html_report --clean ")


    #发送测试报告
    send_feishu_message()
